package com.xframe.common.core.api;


import com.xframe.domain.CredentialsContainer;
import com.xframe.domain.role.IUserCredentials;
import com.xframe.common.core.dto.*;
import com.xframe.common.core.exception.BusinessException;


/**
 * 功能描述:基础Controller
 *
 * @author xufeng
 * @version 1.0
 * 2022-09-26
 */
public abstract class BaseController {


    /**
         * 检查等钱的登录令牌  model
     *
     * @return IUserCredentials用户信息
     */
    protected IUserCredentials checkUserToken() {
        return checkUserToken(true);
    }
    /**
     * 检查等钱的登录令牌
     * @param checkExp true 没有令牌则排除异常
     *
     * @return IUserCredentials用户信息
     */
    protected IUserCredentials checkUserToken(boolean checkExp) {

        IUserCredentials userCredentials = CredentialsContainer.getCredentials();

        if (checkExp && userCredentials == null) {
            throw new BusinessException(ErrorCode.TOKEN_ERROR, "登录过期，请重新登录");
        }
        return userCredentials;
    }



}
